package org.soc.timesheet.server.domain.service;

import java.util.List;
import org.soc.timesheet.domain.Projects;
import org.soc.timesheet.domain.repository.ProjectsRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class ProjectsServiceImpl implements ProjectsService {

	@Override
	public Page<Projects> findByFilters(Specification<Projects> filter,
			Pageable pageable) {
		// TODO Auto-generated method stub
		return projectsRepository.findAll(filter, pageable);
	}

	@Override
	public Page<Projects> findAll(Pageable pageable) {
		// TODO Auto-generated method stub
		return projectsRepository.findAll(pageable);
	}
	
	

	@Autowired
    ProjectsRepository projectsRepository;

	public long countAllProjectses() {
        return projectsRepository.count();
    }

	public void deleteProjects(Projects projects) {
        projectsRepository.delete(projects);
    }

	public Projects findProjects(Integer id) {
        return projectsRepository.findOne(id);
    }

	public List<Projects> findAllProjectses() {
        return projectsRepository.findAll();
    }

	public List<Projects> findProjectsEntries(int firstResult, int maxResults) {
        return projectsRepository.findAll(new org.springframework.data.domain.PageRequest(firstResult / maxResults, maxResults)).getContent();
    }

	public void saveProjects(Projects projects) {
        projectsRepository.save(projects);
    }

	public Projects updateProjects(Projects projects) {
        return projectsRepository.save(projects);
    }
}
